package com.felix.util;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.felix.bean.Carshare;
import com.felix.bean.User;
import com.g3net.tool.CTime;
import com.google.common.base.Joiner;

public class SplitData {
	public static Map<String, Object> SplitByDate(List<Carshare> shares,List<String> dates){
		List<Carshare> shList=null;
		String tempDate=null;
		Calendar cal=Calendar.getInstance();

		Map<String, Object> map =new TreeMap<String, Object>();
		for (String d:dates) {
			shList=new ArrayList<Carshare>();
			for(Carshare sh:shares){
				if (d.equals(sh.getGotime().substring(0, 10))) {
					shList.add(sh);
				}
			}
//			tempDate=CTime.formatRealDate(cal.getTime());
//			if (tempDate.equals(d)) {
//				map.put("今天", shList);
//			}else {
//				
//			}
			map.put(d, shList);
		}

		return map;
	}
	
	public static String CidStrBuilder(List<Carshare> list){
		StringBuffer sb =new StringBuffer();
		for (Carshare csh:list) {
			sb.append(csh.getCid()+",");
		}
		System.out.println("leng="+sb.length());
		if (sb.length()>0) {
			sb.deleteCharAt(sb.length()-1);
		}else {
			return null;
		}
		
		
		return sb.toString();
		
	}
	
	public static String CityStrBuilder(List<String> list){
		StringBuffer sb =new StringBuffer();
		for (String city:list) {
			sb.append("'"+city+"',");
		}
		System.out.println("leng="+sb.length());
		if (sb.length()>0) {
			sb.deleteCharAt(sb.length()-1);
		}else {
			return null;
		}
		
		
		return sb.toString();
		
	}
	
	public static void addJoinerToList(List<Carshare> carshares,List<User> joiners){
		List<User> js=null;
		for(Carshare csh: carshares){
			js=new ArrayList<User>();
			for(User j:joiners){
				if (csh.getCid()==j.getTb_cid()) {
					js.add(j);
				}
			}
			csh.setTb_joiners(js);
		}
		
	}

}
